<?php
class UserGroup extends ModelBase
{
	private $tableName = 'myadmin_user_group';
	
	public static function getInstance()
	{
		return parent::instance(__CLASS__);
	}
	
	public function getGroupInfo($gid)
	{
		$user = Yii::app()->db->createCommand()
		->select('*')
		->from($this->tableName)
		->where('group_id=:group_id', array(':group_id'=>$gid))
		->queryRow();
		return $user;
	}
		
	public function getGroups()
	{		
		$user = Yii::app()->db->createCommand()
		->select('a.*,b.user_name as owner_name')
		->from($this->tableName.' a')
		->leftJoin('myadmin_user b', 'b.user_id=a.owner_id')
		->queryAll();
		return $user;
	}
	
	public function delGroup($gid)
	{
		if(!$gid)
		{
			return false;
		}
		$ret = Yii::app()->db->createCommand()->delete($this->tableName,'group_id = '.$gid);
		return $ret;
	}
	
	public function insertGroup($data)
	{
		$ret = Yii::app()->db->createCommand()->insert($this->tableName,$data);
		return $ret; 
	}
	
	public function updateGroup($data,$gid)
	{
		$ret = Yii::app()->db->createCommand()->update($this->tableName, $data,'group_id = '.$gid);
		return $ret;
	}	
}